<template>
  <div>
    <r-treenode
      v-for="item in items"
      :key="item[itemkey]"
      :data="item"
      :rkey="item[itemkey]"
      :text="item[itemtext]"
      :items="item.children"
      :isdir="item.isdir"
      :color="color"
    >
    </r-treenode>
  </div>
</template>

<script>
import RTreenode from "./RTreenode";

export default {
  name: "RTree",
  data() {
    return {
      // 存储节点状态数据，例如激活等
      store: {
        active: {}, // 使用节点唯一的值作为键值
        show: {},
      },
      change: false, // 用于表示当前所有子节点发生变化
      dirOpenIcon:"mdi-folder-open-outline",
      dirCloseIcon:"mdi-folder-outline",
      fileIcon:"mdi-file-document-outline",
    };
  },
  props: {
    items: {
      type: Array,
    },
    itemkey: { type: String },
    itemtext: { type: String },
    color: {type: String},
  },
  components: { RTreenode },
  methods: {
    toggleData(attr, key) {
      this.store[attr][key] = !this.store[attr][key];
      this.change = !this.change;
    },
    setData(status, key, val) {
        if(this.store[status] == null) {
          this.store[status] = {}
        }
        this.store[status][key] = val
        this.change = !this.change;
    },
    setOnceData(status, key, val){
      this.store[status]  = {}
      this.setData(status, key, val)
    },
    getData(status ,key) {
        if(this.store[status] != null) {
          return this.store[status][key]
        }
        return null
    }
  },

  created() {
    this.isTree = true;
  },
};
</script>
<style scoped></style>
